<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
{{assign var="title" value='数据还原'}}
{{assign var="app" value='database'}}
{{assign var="act" value='index'}}
{{assign var="td" value='7'}}
<title>{{$title}}管理 - {{'admin|admin_site_name'|C|default:'后台管理'}}</title>
{{include file="include/base.html"}}
<script>
$(document).ready(function(){
    $('.left').click(function(){//还原
        if($('.check_id:checked').length==0) { ui.alert("至少选择一条数据!"); return false; }
        $('form[name=form]').attr('action',"{{'index.php?app='|cat:$app|cat:'&act=recovery'|URL}}");
        ui.confirm('当前选中'+$('.check_id:checked').length+'项，确实要还原这些表吗?',function(z){
            if(z){
                $ajaxSubmit.ajaxSubmit($('form'));
            }
        },true);
        return false;
    });
    $('.del').click(function(){//删除
        if($('.check_id:checked').length==0) { ui.alert("至少选择一条数据!"); return false; }
        $('form[name=form]').attr('action',"{{'index.php?app='|cat:$app|cat:'&act=delBak'|URL}}");
        ui.confirm('当前选中'+$('.check_id:checked').length+'项，删除将不可恢复,确定要删除吗?',function(z){
            if(z){
                $ajaxSubmit.ajaxSubmit($('form'));
            }
        },true);
        return false;
    });
    $('select').change(function(){
        document.location.href="{{$smarty.const.__ROOT__}}index.php?app={{$app}}&act=recovery&date="+$(this).val();
    });
});
</script>
</head>
<body>

{{include file="include/sidebar.html"}}

<div class="body_right">
    <div id="content">

    <form name='form' class='ajaxSubmit' action="index.php" method="post">
    <table class="table table-bordered">
        <tr class="thead">
          <td colspan="{{$td}}">
              ◆ {{$title}}管理 －> {{$title}}列表
          </td>
        </tr>
        {{if !$list}}
        <tr class="noline"><td colspan="{{$td}}" class="result_empty"></td></tr>
        {{else}}
        <tr class="ttitle">
            <th width="200">备份名称</th>
            <th width="80">卷数</th>
            <th width="80">压缩</th>
            <th width="80">数据大小</th>
            <th width="200">备份时间</th>
            <th width="135">操作</th>
        </tr>
        <tbody>
            {{foreach from=$list item=val key=key}}
            <tr>
                <td>{{$val.time|date_format:'Ymd-His'}}</td>
                <td>{{$val.part}}</td>
                <td>{{$val.compress}}</td>
                <td>{{$val.size|getFileSize}}</td>
                <td>{{$key}}</td>
                <td class="action">
                    <a class="db-import btn btn-success" href="index.php?app=database&act=import&time={{$val.time}}"><i class="icon-retweet"></i>还原</a>
                    <a class="ajaxSubmit confirm btn btn-danger refresh" title='删除将不可恢复，确定要删除吗？' link="index.php?app=database&act=del&time={{$val.time}}"><i class="icon-trash"></i>删除</a>
                </td>
            </tr>
            {{/foreach}}
        </tbody>
        {{/if}}
    </table>
    </form>
</div>
</div>
<script type="text/javascript">
$(".db-import").click(function(){
	message('开始还原数据库......',0);
    var self = this, status = ".";
    $.get(self.href, success, "json");
    window.onbeforeunload = function(){ return "正在还原数据库，请不要关闭！" }
    return false;

    function success(data){
        if(data.statusCode=='200'){
        	
            if(data.gz){
                data.info += status;
                if(status.length === 5){
                    status = ".";
                } else {
                    status += ".";
                }
            }
            if(data.data.part){
            	message(data.message,0);
                $.get(self.href, 
                    {"part" : data.data.part, "start" : data.data.start}, 
                    success, 
                    "json"
                );
            }  else {
            	message(data.message,3000);
                window.onbeforeunload = function(){ return null; }
            }
        } else {
        	$('.ui_success').prev().hide();
            $('.ui_success').hide();
            ui.alert(data.message);
        }
    }
});


function message(str,time){
	$('.ui_success').prev().hide();
    $('.ui_success').hide();
    ui.success(str,time>0 ? time : 1000000000,true);
}
</script>

</body>
</html>